package com.csu.tour.controller;

import com.csu.tour.common.CommonResponse;
import com.csu.tour.entity.DiningEntertainment;
import com.csu.tour.entity.PerformanceGroup;
import com.csu.tour.service.DiningEntertainmentService;
import com.csu.tour.vo.DiningEntertainmentVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/diningEntertainment")
public class DiningEntertainmentController {
    @Autowired
    private DiningEntertainmentService diningEntertainmentService;

    @GetMapping
    public CommonResponse<List<DiningEntertainment>> getAll() {
        List<DiningEntertainment> diningEntertainmentList = diningEntertainmentService.findAll();
        boolean temp = diningEntertainmentList.isEmpty();
        //数据库查询成功但数据库中没有任何数据
        if (temp) {
            String msg = "当前没有餐饮娱乐";
            return CommonResponse.createForSuccessMessage(msg);
        } else {
            // 创建成功响应，包含数据
            String msg = "数据库查询成功";
            return CommonResponse.createForSuccess(diningEntertainmentList);
        }
    }

    @GetMapping("/food")
    public CommonResponse<List<DiningEntertainment>> getEntertainByFood(@RequestBody DiningEntertainmentVO diningEntertainmentVO) {

        List<DiningEntertainment> diningEntertainmentList = diningEntertainmentService.findByFood(diningEntertainmentVO.getFood());
        boolean temp = diningEntertainmentList.isEmpty();

        //数据库查询成功但数据库中没有任何数据
        if (temp) {
            String msg = "当前没有餐饮娱乐";
            return CommonResponse.createForSuccessMessage(msg);
        } else  {
            // 创建成功响应，包含数据
            String msg = "数据库查询成功";
            return CommonResponse.createForSuccess(diningEntertainmentList);
        }
    }
}